package edu.whcp.comp2301.dao.impl;

import edu.whcp.comp2301.dao.CommentDao;
import edu.whcp.comp2301.mapper.CommentMapper;
import edu.whcp.comp2301.pojo.Comment;
import edu.whcp.comp2301.pojo.News;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class CommentDaoImpl implements CommentDao {
    @Autowired
    private CommentMapper commentMapper;

    @Override
    public List<Comment> getAllComments() {
        List<Comment> commentList=commentMapper.getAllComments();
        for(Comment comment:commentList){
            comment.setNews(getNewsById(comment.getNews()).getTitle());
        }
        return commentList;
    }

    @Override
    public News getNewsById(String id) {
        return commentMapper.getNewsById(id);
    }

    @Override
    public void checkComment(String status, String id) {
        commentMapper.checkComment(status,id);
    }

    @Override
    public Integer delComment(List<String> idList) {
        return commentMapper.delComment(idList);
    }

    @Override
    public List<Comment> getComm(String id) {
        return commentMapper.getComm(id);
    }

    @Override
    public Integer addComment(Comment comment) {
        return commentMapper.addComment(comment);
    }
}
